﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ProgramMain.Framework;

namespace ProgramMain.Parameters
{
    public partial class ProgramParametersCtl : ProgramMain.Framework.BaseDetailCtl
    {
        public ProgramParametersCtl()
        {
            InitializeComponent();
        }

        public DialogResult ShowModal()
        {
            return ProgramMain.Framework.frmBaseModal.ShowModal(this, labelCaption.Text, this.btnSave, this.btnCancel);
        }

        override public void OnLoadControl(object sender, EventArgs e)
        {
            this.BindData();
        }

        void BindData()
        {
            spinDBTimeout.Value = Properties.Settings.Default.LongQueryTimeout;
            
            checkDownloadFromGoogle.Checked = Properties.Settings.Default.DownloadImagesFromGoogle;
            checkWriteMapCache.Checked = Properties.Settings.Default.WriteMapCache;
            txtEditMapPath.Text = Properties.Settings.Default.MapPath;
            checkShowTranzitVertexNames.Checked = Properties.Settings.Default.ShowVertexNamesTranzit;
            checkAutoShowMap.Checked = Properties.Settings.Default.AutoShowMap;
            checkShowVertexNames.Checked = Properties.Settings.Default.ShowVertexNames;
            checkShowCableTunnelNames.Checked = Properties.Settings.Default.ShowCableTunnelNames;
            checkShowObjectName.Checked = Properties.Settings.Default.ShowObjectName;
            labelMapColor.ForeColor = Properties.Settings.Default.MapCaptionColor;
            spinPutRuleDistance.Value = Properties.Settings.Default.PutRuleDistance;
            checkIsPutRule.Checked = Properties.Settings.Default.IsPutRule;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.LongQueryTimeout = Convert.ToInt32(spinDBTimeout.Value);

            Properties.Settings.Default.DownloadImagesFromGoogle = checkDownloadFromGoogle.Checked;
            Properties.Settings.Default.WriteMapCache = checkWriteMapCache.Checked;
            Properties.Settings.Default.MapPath = txtEditMapPath.Text;
            Properties.Settings.Default.MapCaptionColor = labelMapColor.ForeColor;
            Properties.Settings.Default.AutoShowMap = checkAutoShowMap.Checked;
            Properties.Settings.Default.ShowVertexNames = checkShowVertexNames.Checked;
            Properties.Settings.Default.ShowVertexNamesTranzit = checkShowTranzitVertexNames.Checked;
            Properties.Settings.Default.ShowCableTunnelNames = checkShowCableTunnelNames.Checked;
            Properties.Settings.Default.ShowObjectName = checkShowObjectName.Checked;
            Properties.Settings.Default.PutRuleDistance = (int) spinPutRuleDistance.Value;
            Properties.Settings.Default.IsPutRule = checkIsPutRule.Checked;
            Properties.Settings.Default.Save();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.UserName = "";
            Properties.Settings.Default.UserPassword = "";
            Properties.Settings.Default.Save();
            XtraMessageBox.Show("Сохраненные пароль и имя пользователя были удалены c локального компьютера", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Для сброса настроек, требуется закрытие все окон. Продолжить?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
            GlobalData.ClearHistory();
        }

        private void panelColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog( ) == DialogResult.OK)
                labelMapColor.ForeColor = colorDialog1.Color;
        }
    }
}
